﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Modellayer;
using Dblayer;
using System.Runtime.Serialization;
using System.Threading;
using System.Globalization;


namespace Controllayer
{
    [DataContract]
    public class ShowCtr
    {
        private DbShow dbS;
        private DbSeat dbsE;
        private DbMovie dbM;
        private DbShowRoom dbSh;
        private DbPerson dbP;

        public ShowCtr()
        {
            dbS = new DbShow();
            dbsE = new DbSeat();
            dbM = new DbMovie();
            dbSh = new DbShowRoom();
            dbP = new DbPerson();


        }

        public Show createShow(Movie movie, ShowRoom showRoom, int showId, string dt)
        {
            Show s = new Show(movie, showRoom, showId, dt);

            dbS.createShow(s);
            return s;
        }

        public Show updateShow(Show s)
        {

            dbS.updateShow(s);
            return s;
        }

        public void LockSeat(int ShowId, int seatNumber)
        {
            Show show = dbS.findShow(ShowId);
            show.lockSeat(seatNumber);
        }

        public void ReserveSeat(int ShowId, int seatNumber, int reservationsId)
        {
            Show show = dbS.findShow(ShowId);
            show.reserveSeat(seatNumber, reservationsId);
        }

        public void unLockSeat(int showId, int seatNumber)
        {
            Show show = dbS.findShow(showId);
            show.unLockSeat(seatNumber);
        }
        public List<Seat> getAllSeatsByShowId(int ShowId)
        {
            List<Seat> seat = dbsE.findSeatByShowId(ShowId);
            return seat;
        }

        public List<Seat> getAllSeatsByReservationID(int ReservationID)
        {
            List<Seat> Seat = dbsE.findSeatByReservationsID(ReservationID);
            return Seat;
        }

        public Movie createMovie(string Title, string movieLength, string MovieDescription)
        {
            Movie m = new Movie(Title, movieLength, MovieDescription);
            dbM.createMovie(m);
            return m;
        }

        public Movie updateMovie(string Title, string movieLength, string MovieDescription)
        {
            Movie m = new Movie(Title, movieLength, MovieDescription);
            dbM.updateMovie(m);
            return m;
        }

        public List<Show> findAllShows()
        {

            List<Show> shows = new List<Show>();

            foreach (Show s in dbS.findAllShows())
            {
                int index = 0;
                int index2 = 0;
                if (dbS.findAllShows().ElementAt(index).movie.Title != s.movie.Title)
                {
                    s.getAllShow = dbM.findAllMovies();

                }

                else
                {
                    index++;
                }

                if (dbS.findAllShows().ElementAt(index2).showroom.showRoomNumber != s.showroom.showRoomNumber)
                {
                    s.getAllShowRoom = dbSh.findAllShowRooms();
                    index2++;
                }

                else
                {
                    index2++;
                }

                shows.Add(s);
            }

            return shows;
            //return dbS.findAllShows();
        }

        public Show findShow(int showId)
        {
            Show s = dbS.findShow(showId);
            return s;
        }

        public Movie findMovie(string Title)
        {
            Movie m = dbM.findMovie(Title);
            return m;
        }

        public List<Movie> findAllMovie()
        {

            List<Movie> m = dbM.findAllMovies();
            return m;


        }
    }
}
